﻿@using Squidex.Areas.IdentityServer.Controllers.Account
@model Squidex.Areas.IdentityServer.Controllers.Account.LoginVM

@{
    ViewBag.Title = T.Get("common.login");
}

<div class="login-container">
    <div>
        @if (Model.HasExternalLogin)
        {
            <form asp-controller="Account" asp-action="External" asp-route-returnurl="@Model.ReturnUrl" method="post">
                @Html.AntiForgeryToken()

                @foreach (var provider in Model.ExternalProviders)
                {
                    var schema = provider.AuthenticationScheme.ToLowerInvariant();

                    <div class="form-group mb-2">
                        <button class="btn external-button btn-block btn btn-@schema" type="submit" name="provider" value="@provider.AuthenticationScheme">
                            <i class="icon-@schema external-icon"></i> @Html.Raw(T.Get("users.login.loginWith", new { action = T.Get("common.login"), provider = provider.DisplayName }))
                        </button>
                    </div>
                }
            </form>
        }

        <div class="profile-separator">
            <div class="profile-separator-text">@T.Get("users.login.separator")</div>
        </div>

        @if (Model.HasPasswordAuth)
        {
            <div>
                @if (Model.RequestType == RequestType.Login)
                {
                    <div asp-validation-summary="ModelOnly" class="form-alert form-alert-error"></div>
                }

                <form asp-controller="Account" asp-action="Login" asp-route-returnurl="@Model.ReturnUrl" method="post">
                    @Html.AntiForgeryToken()

                    <div class="form-group">
                        <div error-for="Email"></div>
                        <input asp-for="Email" type="email" class="form-control" placeholder="@T.Get("users.login.emailPlaceholder")" />
                    </div>

                    <div class="form-group">
                        <div error-for="Password"></div>
                        <input asp-for="Password" type="password" class="form-control" placeholder="@T.Get("users.login.passwordPlaceholder")" autocomplete="off" />
                    </div>

                    <button type="submit" data-testid="login-button" class="btn btn-block btn-primary">@T.Get("common.login")</button>
                </form>
            </div>
        }

        <div class="profile-separator">
            <div class="profile-separator-text">@T.Get("users.login.separator")</div>
        </div>

        @if (Model.HasCustomAuth)
        {
            <div>
                @if (Model.RequestType == RequestType.LoginCustom)
                {
                    <div asp-validation-summary="ModelOnly" class="form-alert form-alert-error"></div>
                }

                <div class="mb-2">
                    <small class="text-muted form-text">@T.Get("users.login.custom")</small>
                </div>

                <form asp-controller="Account" asp-action="LoginDynamic" asp-route-returnurl="@Model.ReturnUrl" method="post">
                    @Html.AntiForgeryToken()

                    <div class="form-group">
                        <div error-for="DynamicEmail"></div>
                        <input asp-for="DynamicEmail" type="email" class="form-control" placeholder="@T.Get("users.login.emailBusinessPlaceholder")" />
                    </div>

                    <button type="submit" data-testid="dynamic-button" class="btn btn-block btn-primary">@T.Get("common.login")</button>
                </form>
            </div>
        }
    </div>
</div>